<template>
	<div class="header-wrap">
		<el-row :gutter="20">
			<el-col class="header-left" :span="16">
				<span class="el-icon-back" @click="handleBack"></span>
				<h2>{{ title }}</h2>
				<h1 @click="handleBack">
					<i class="el-icon-notebook-2"></i>
					{{ courseInfo.title }}
				</h1>
			</el-col>
			<el-col class="header-right" :span="8">
				<span class="el-icon-bell"></span>
				<div class="user-avatar">
					<el-avatar class="avatar" size="large" :src="userPture || headPic"></el-avatar>
					<div class="user-wrap">
						<el-row :gutter="20">
							<el-col :span="8">
								<el-avatar class="avatar" :size="60" :src="userPture || headPic"></el-avatar>
							</el-col>
							<el-col :span="16">
								<span>{{ username }}</span>
							</el-col>
						</el-row>
						<el-divider></el-divider>
						<el-row :gutter="20" class="btns">
							<el-col :span="12">
								<span>我的课程</span>
							</el-col>
							<el-col :span="12">
								<span>个人设置</span>
							</el-col>
						</el-row>
						<el-divider></el-divider>
						<div style="text-align: right">
							<el-button type="text" icon="el-icon-switch-button">退出</el-button>
						</div>
					</div>
				</div>
			</el-col>
		</el-row>
	</div>
</template>
<script>
import userInfo from '@/mixins/userInfo.js';
import webinfo from '@/mixins/webinfo.js';
export default {
	mixins: [userInfo, webinfo],
	data() {
		return {
			resource: {}
		};
	},
	computed: {
		title() {
			let { sort } = this.$route.query;
			return sort || this.resource.name ? '1.1.1' + this.resource.name : '暂无数据';
		}
	},
	props: ['courseInfo'],
	mounted() {
		this.$bus.$on('sendResourceInfo', (v) => {
			this.resource = v;
		});
	},
	beforeDestroy() {
		this.$bus.$off('sendResourceInfo');
	},
	methods: {
		handleBack() {
			let { id } = this.$route.query;
			this.$router.push({
				name: 'course-home-detail',
				query: { id }
			});
		}
	}
};
</script>
<style scoped lang="scss">
.header-wrap {
	position: relative;
	padding-right: 24px;
	height: 60px;
	line-height: 60px;
	background: #fff;
	.header-left {
		span {
			float: left;
			line-height: 60px;
			padding: 0 20px;
			font-size: 22px;
			color: #666;
			cursor: pointer;
			transition: all 0.3s;
			&:hover {
				background: #f5f5f5;
			}
		}
		h2 {
			float: left;
			font-size: 16px;
			color: #1c1f21;
			font-weight: 700;
		}
		h1 {
			float: left;
			font-size: 18px;
			color: #333;
			cursor: pointer;
			transition: all 0.3s;
			&:hover {
				color: red;
			}
			i {
				font-size: 18px;
				color: #aaa;
			}
		}
		i {
			font-size: 14px;
			color: #666;
			margin-left: 20px;
			cursor: pointer;
			&:hover {
				color: #333;
			}
		}
	}
	.header-right {
		position: relative;
		text-align: right;
		span {
			font-size: 20px;
			line-height: 60px;
			cursor: pointer;
		}
		.user-avatar {
			position: relative;
			margin-left: 50px;
			float: right;
			&:hover {
				.user-wrap {
					display: block;
				}
			}
			.avatar {
				float: right;
				margin-top: 10px;
				cursor: pointer;
			}
			.user-wrap {
				display: none;
				text-align: left;
				position: absolute;
				right: 0;
				top: 50px;
				width: 300px;
				padding: 0 20px;
				background: #ffff;
				// border: 1px solid #ccc;
				// border-top: 1px solid #eee;
				box-sizing: border-box;
				border-bottom-right-radius: 5px;
				border-bottom-left-radius: 5px;
				z-index: 999;
				box-shadow: 0 3px 8px 0 rgba(0, 0, 0, 0.3);
				span {
					font-size: 14px;
				}
				.btns {
					span {
						display: inline-block;
						width: 100%;
						height: 32px;
						text-align: center;
						line-height: 32px;
						border-radius: 3px;
						background-color: #f8fafc;
						&:hover {
							background-color: #d9dde1;
						}
					}
				}
			}
		}
	}
}
</style>
